<template>
  <div>
    <el-dialog title="设置" :visible.sync="dialogVisible" width="450px">
      <el-form label-width="100px" :model="form" :rules="rules" ref="form" size="small">
        <el-form-item label="吨毛利:" prop="aboutPerProfit">
          <el-input type="text"  v-model="form.aboutPerProfit"  clearable style="width:200px">
          </el-input>
        </el-form-item>
        <el-form-item label="月销量:" prop="aboutBuyNum">
          <el-input type="text" placeholder="请输入月销量" v-model="form.aboutBuyNum" clearable style="width:200px">
          </el-input>
        </el-form-item>
        <!-- <el-form-item label="开发难易度:" prop="trackingDifficultyId">
            <el-select v-model="form.trackingDifficultyId" clearable>
                <el-option v-for="item in difficultytList" :value="item.difficultyId" :label="item.difficultyName" :key="item.difficultyId"></el-option>
            </el-select>
        </el-form-item> -->
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
// import { getDifficultytListAPI } from "@/api/fms.js";
import {updateCustomerMy} from "@/api/company"
const defaultForm = {
  aboutPerProfit: "",  // 吨毛利
  aboutBuyNum: "", //月销量
  //trackingDifficultyId: 0, //开发难易度
  dataId:''
};
export default {
  name: "settingCustomer",
  data() {
    return {
      dialogVisible: false,
      form: JSON.parse(JSON.stringify(defaultForm)),
      rules: {
        aboutPerProfit: [
          { required: true, message: '此项必填', trigger: 'blur' },
        ],
        aboutBuyNum: [
          { required: true, message: '此项必填', trigger: 'blur' },
        ],
        // trackingDifficultyId: [
        //   { required: true, message: '此项必填', trigger: 'change' },
        // ],
      },
      btnLoading:false,
      // difficultytList:[]
    };
  },
  created() {
  },
  methods: {
    //获取难易系数列表
    // getDifficultytList(){
    //   getDifficultytListAPI({pageNum:1,pageSize: 1000,isEnable:1}).then((res)=>{
    //      this.difficultytList = res.list
    //   })
    // },
    // 提交
    handleConfirm() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.btnLoading = true;
          let data = JSON.parse(JSON.stringify(this.form))
          updateCustomerMy(data).then((res)=>{
            this.btnLoading = false;
            this.handleClose();
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            this.$emit('getList');
          }).catch(()=>{
            this.btnLoading = false;
          })
        } else {
          return false;
        }
      })
    },
    // 回显
    showPop(item) {
      this.dialogVisible = true;
      // this.getDifficultytList()
      this.form = JSON.parse(JSON.stringify(defaultForm))
      this.form.aboutPerProfit = item.aboutPerProfit;
      this.form.aboutBuyNum = item.aboutBuyNum
      // this.form.trackingDifficultyId = item.trackingDifficultyId ? item.trackingDifficultyId: ''
      this.form.dataId = item.dataId
    },
    // 关闭弹框
    handleClose() {
      this.$refs.form.resetFields();
      this.dialogVisible = false;
    },
  },
};
</script>

